#include<vector>
using namespace std;

struct ListNode {
    int val;
    ListNode* next;
    ListNode(int x) : val(x), next(NULL) {}
};
 
class Solution {
public:
    ListNode* oddEvenList(ListNode* head) {
        if (head == NULL||head->next==NULL) return head;
        ListNode* even = head;
        ListNode* odd = head->next;
        ListNode* odd1 = odd;
        ListNode* node = head->next->next;
        bool isEven = true;
        while (node != NULL) {
            if (isEven) {
                even->next = node;
                even = even->next;
            }
            else {
                odd->next = node;
                odd = odd->next;
            }
            isEven = !isEven;
            node = node->next;
        }
        odd->next = NULL;
        even->next = odd1;
        return head;

    }
};